package util.texture.textureGenerators;

import java.awt.Dimension;
import java.awt.geom.AffineTransform;
import java.nio.FloatBuffer;
import util.Color4F;
import util.Vec2F;
import util.Vec2I;

/**
 * Generates a block of floating point texture data appropriate for 
 * @author stephenpheiffer
 *
 */
public abstract class BaseFloatTextureDataGenerator
{
	private float integral;
	protected BaseFloatTextureDataGenerator()
	{
	}
	public FloatBuffer generate(Dimension dimension)
	{
		FloatBuffer data = FloatBuffer.allocate(dimension.width * dimension.height * 4);
		AffineTransform t = new AffineTransform();
		t.scale(2.0f/dimension.width, 2.0f/dimension.height);
		t.translate(-dimension.width / 2.0 + 0.5, -dimension.height / 2.0  + 0.5);
		
		integral = 0;
		int index = 0;
		for(int y=0;y<dimension.height;y++)
			for(int x=0;x<dimension.width;x++)
			{
				Color4F color = texelValue(new Vec2F(x,y).GetTransform(t));
                data.put(index + 0, color.red);
				data.put(index + 1, color.green);
                data.put(index + 2, color.blue);
				data.put(index + 3, color.alpha);
				index +=4;
				integral += (color.red + color.green + color.blue) * color.alpha;
			}
		return data;
	}
	/**
	 * Gets called across the texture asking for a value on the range -1 to 1.
	 * @param location
	 * @return
	 */
	abstract protected Color4F texelValue(Vec2F location);
	public float getIntegral()
	{
		return integral;
	}
	

}
